package org.middleware.service;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.security.SecureRandom;
import java.util.*;

@SpringBootTest
public class test {

    /**
     * 验证 jwt 的密钥
     *
     * @param secret 密钥
     * @return true/false
     */
    @Test
    public void validatorSecret(String secret) {
        try {
            byte[] decoded = Base64.getDecoder().decode(secret);
            System.out.println("密钥有效，长度: " + decoded.length + " 字节");
            System.out.println("Base64编码: " + secret);
        } catch (IllegalArgumentException e) {
            System.out.println("密钥无效: " + e.getMessage());
        }
    }

    /**
     * 生成 Jwt 的密钥
     *
     * @return 密钥
     */
    @Test
    public void createSecret() {

        SecureRandom random = new SecureRandom();
        byte[] key = new byte[32]; // 256位，适合HS512算法
        random.nextBytes(key);
        String secret = Base64.getEncoder().encodeToString(key);
        System.out.println("新生成的JWT Secret: " + secret);
    }

    @Test
    public void test() {
        for (int i = 1; i <= 20; i++) {
        }
    }

    @Test
    public int[] test2() {
        int[] nums = {2, 7, 11, 15};
        int target = 9;

        Map<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            int complement = target - nums[i];
            if (map.containsKey(complement)) {
                return new int[]{map.get(complement), i};
            }
            map.put(nums[i], i);
        }
        System.out.println(map);
        return new int[0];
    }

}
